package com.fenshi.manager.activity.order;

import android.app.ProgressDialog;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.fenshi.bean.OrderBean;
import com.fenshi.manager.R;
import com.fenshi.presenter.imp.OrderPresenterImp;
import com.fenshi.view.OrderDetailView;
import com.quickdv.activity.BaseActivity;
import com.quickdv.until.AlertHelper;

import butterknife.InjectView;
import butterknife.OnClick;

public class OrderDetailActivity extends BaseActivity implements View.OnClickListener ,OrderDetailView {

    ProgressDialog load;
    OrderPresenterImp presenter;


    @InjectView(R.id.order_code)
    TextView orderCode;
    @InjectView(R.id.order_user)
    TextView orderUser;
    @InjectView(R.id.order_type)
    TextView orderType;
    @InjectView(R.id.order_create_time)
    TextView orderCreateTime;
    @InjectView(R.id.order_back_car_time)
    TextView orderBackCarTime;
    @InjectView(R.id.order_car_distance)
    TextView orderCarDistance;
    @InjectView(R.id.order_consume_time)
    TextView orderConsumeTime;
    @InjectView(R.id.order_cost)
    TextView orderCost;
    @InjectView(R.id.order_back_car_number)
    TextView orderBackCarNumber;
    @InjectView(R.id.order_mileagecost)
    TextView orderMileagecost;
    @InjectView(R.id.order_mileagecost_money)
    TextView orderMileagecostMoney;
    @InjectView(R.id.order_baseictariff)
    TextView orderBaseictariff;
    @InjectView(R.id.order_baseictariff_money)
    TextView orderBaseictariffMoney;
    @InjectView(R.id.order_cs_time_cost_money)
    TextView orderCsTimeCost;
    @InjectView(R.id.order_limit_cost)
    TextView orderLimitCost;
    @InjectView(R.id.current_car_location)
    LinearLayout currentCar;

    @Override
    public int getLayoutID() {
        return R.layout.activity_order_detail;
    }

    @Override
    public void initView() {
        AlertHelper helper = new AlertHelper(this);
        load = helper.LoadingAlert();
        presenter = new OrderPresenterImp(this);
        presenter.getOrder();


    }

    @Override
    public void initActionbar() {

    }

    @Override
    public void initData() {

    }

    @OnClick({R.id.current_car_location})
    @Override
    public void onClick(View view) {
       switch (view.getId()){
           case R.id.current_car_location:
               presenter.CurrentCar();
               break;
       }
    }


    @Override
    public void showLoad() {
        if (load!=null  && !load.isShowing()) load.show();
    }

    @Override
    public void dismissLoad() {
        if (load!=null  && load.isShowing()) load.dismiss();
    }

    @Override
    public void showError(String error) {
        Toast.makeText(this,error,Toast.LENGTH_LONG).show();
    }

    @Override
    public void refreshView(OrderBean orderBean) {

        Log.e("", JSON.toJSONString(orderBean));
        orderCode.setText(orderBean.getOrderCode());
        orderUser.setText(orderBean.getUserName());
        orderCreateTime.setText(orderBean.getCreateTime());
        orderBackCarTime.setText(orderBean.getEndTime());
        orderCarDistance.setText(orderBean.getDistance() + "");
        orderConsumeTime.setText(orderBean.getOrderTime());
        orderCost.setText("¥" +orderBean.getMoney() + "");
        if (orderBean.getStatus().equals("1") || orderBean.getStatus().equals("2")) {
            orderType.setText("订单使用中");
            orderType.setTextColor(getResources().getColor(R.color.red));
        }else
            currentCar.setVisibility(View.GONE);


        orderLimitCost.setText("¥" +orderBean.getExpense());
        orderBackCarNumber.setText(orderBean.getCarName());

        float time =Math.round(orderBean.getBasictariff()*100);
        orderBaseictariff.setText("x " + time/100.0 + "元/分钟");
        float timeMoney =Math.round(orderBean.getOrderTimeMoney()*100.0);
        orderBaseictariffMoney.setText("金额:¥" + timeMoney/100.0);

        float mile =Math.round(orderBean.getMileagecost()*100);
        orderMileagecost.setText("x "+mile/100.0 + "元/公里");
        float distanceMoney =Math.round(orderBean.getDistanceMoney()*100.0);
        orderMileagecostMoney.setText("金额:¥"+ distanceMoney/100.0);

        orderCsTimeCost.setText("¥" +orderBean.getCsTimeMoney());
    }

}
